using System;
using System.Collections.Generic;
using System.Text;
using GameStateManager;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace ScreenTest.Screens
{
    class PlayerWonScreen : GameScreen
    {
        ContentManager content = null;
        SpriteFont winnerFont;
        String text;

        float presentationTime = 5f;
        float currentPresentationTime = 5f;

        public PlayerWonScreen(int player)
        {
            text = "Player " + player.ToString() + " Won!";
        }

        public override void LoadGraphicsContent(bool loadAllContent)
        {
            if (content == null)
            {
                content = new ContentManager(ScreenManager.Game.Services);
                winnerFont = content.Load<SpriteFont>(@"Fonts\Winner");
            }
        }

        public override void UnLoadGraphicsContent(bool unloadAllContent)
        {
            content.Unload();
        }

        public void StarTimer()
        {
            currentPresentationTime = presentationTime;
        }

        public override void Update(GameTime gameTime, bool otherScreenHasFocus)
        {
            currentPresentationTime -= (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (currentPresentationTime <= 0f)
            {
                ScreenManager.RemoveScreen(this);
            }
        }

        public override void Draw(GameTime gameTime)
        {
            ScreenManager.FadeBackBufferToBlack(50);

            Rectangle fullscreen = ScreenManager.GetTitleSafeArea();
            //Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
            //Rectangle fullscreen = new Rectangle(0, 0, viewport.Width, viewport.Height);
            Vector2 origin = new Vector2(0, winnerFont.LineSpacing / 2);
            Vector2 size = winnerFont.MeasureString(text);
            Vector2 position = new Vector2(fullscreen.Width/2 - size.X/2,fullscreen.Height/2 - size.Y/2);

            ScreenManager.SpriteBatch.Begin();
            ScreenManager.SpriteBatch.DrawString(winnerFont, text, position, Color.White, 0f, origin, 1f, SpriteEffects.None, 0f);
            ScreenManager.SpriteBatch.End();
        }
    }
}
